#include<stdio.h>
#include<stdlib.h>

typedef struct SList
{
  struct SList* next;
  int data;
}SList;

void Print(SList* plist)
{
  while(plist!=NULL)
  {
    printf("%d",plist->data);
    plist=plist->next;
  }
}

void newnodeSList(SList** plist,int* array,int n)
{
  int i=0;
  while(i<n)
  {
  SList* newnode=(SList*)malloc(sizeof(SList));
  if(newnode==NULL)
  {
    printf("malloc fail!");
    exit(-1);
  }
  newnode->next=NULL;
  newnode->data=array[i];
  i++;
  if(*plist==NULL)
  {
    *plist=newnode;
  }
  else
  {
    SList* cur=*plist;
    while(cur->next!=NULL)
    {
      cur=cur->next;
    }
    cur->next=newnode;
  }
}

void SwapHead(SList** plist)
{
  SList* cur=*plist->next;

  (*plist)->next=(*plist)->next->next;
  (*plist)->next->next=*plist;
  *plist=cur;
}

void SwapTail(SList** plist)
{
  SList* cur=*plist;
  while(cur->next->next->next!=NULL)
  {
    cur=cur->next;
  }
  SList* tail=*plist;
  while(tail->next!=NULL)
  {
    tail=tail->next;
  }
  cur->next=tail;
  tail->next=cur->next;
  cur->next->next=NULL;
}

int main()
{
  int n=0;
  scanf("%d",&n);
  int array[100]={0};
  for(int i=0;i<n;i++)
  {
    scanf("%d",&array[i]);
  }

  SList* phead=NULL;

  newnodeSList(&phead,array,n);

  SwapHead(&phead);

  SwapTail(&phead);

  Print(phead);

  return 0;

}
